//
//  BJHeaderView.m
//  DangXiao
//
//  Created by APPLE on 16/12/6.
//  Copyright © 2016年 APPLE. All rights reserved.
//

#import "BJHeaderView.h"

@implementation BJHeaderView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}

- (void)initUI{
    _headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, BILIHEIGHT(240))];
    _headerView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_headerView];
    
    _headerImageView = [[UIImageView alloc]init];
    _headerImageView.backgroundColor = BaseColor;
    _headerImageView.image = [UIImage imageNamed:@"333"];
    [_headerView addSubview:_headerImageView];
    [_headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth, BILIHEIGHT(170)));
    }];
    
    _contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(BILIWIDTH(10), BILIHEIGHT(180), ScreenWidth - BILIWIDTH(20), BILIHEIGHT(20))];
    _contentLabel.textColor = GrayTextColor;
    _contentLabel.font = FontVlaue(15);
    _contentLabel.numberOfLines = 0;
    [_headerView addSubview:_contentLabel];
    
    UILabel *bottomLabel = [Utils labelWithTitle:@"" titleFontSize:16 textColor:ClearColor backgroundColor:GrayLabel alignment:1];
    [_headerView addSubview:bottomLabel];
    [bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(_headerView.mas_bottom).offset(0);
        make.left.mas_equalTo(_headerView.mas_left).offset(0);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth, BILIHEIGHT(10)));
    }];
    
    _contentLabel.text = @"摘要：卡圣jfdksajkdfj立刻就付款圣诞节疯狂的萨克烦大叔级；案件发考老师的；方尽快的；撒发生可；房间开第三方卡圣jfdksajkdfj立刻就付款圣诞节疯狂的萨克烦大叔级；案件发考老师的；方尽快的；撒发生可；房间开第三方";
    _contentLabel.font = FontVlaue(15);
    _contentLabel.lineBreakMode = NSLineBreakByCharWrapping;
    CGSize maximumLabelSize = CGSizeMake(ScreenWidth - BILIWIDTH(20), 9999);
    CGSize expectSize = [_contentLabel sizeThatFits:maximumLabelSize];
    _contentLabel.frame = CGRectMake(BILIWIDTH(10), BILIHEIGHT(180), expectSize.width, expectSize.height);
    
    NSRange range = [_contentLabel.text rangeOfString:@"摘要："];

    [self setTextColor:_contentLabel FontNumber:FontVlaue(15) AndRange:range AndColor:[UIColor redColor]];
    
    CGRect A = _headerView.frame;
    A.size.height = BILIWIDTH(170) + BILIHEIGHT(25)+ expectSize.height;
    _headerView.frame = A;

}

-(void)setTextColor:(UILabel *)label FontNumber:(id)font AndRange:(NSRange)range AndColor:(UIColor *)vaColor {
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:label.text];
    //设置字号
    [str addAttribute:NSFontAttributeName value:font range:range];
    //设置文字颜色
    [str addAttribute:NSForegroundColorAttributeName value:vaColor range:range];
    label.attributedText = str;
}




@end
